home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / evilswitch.swf / scripts / DefineSprite_63 / frame_2 / DoAction.as
Encoding:
Text File  |  2007-09-27  |  10.5 KB  |  398 lines

  1. function SmallGrid(aRange)
  2. {
  3.    this.init();
  4. }
  5. SmallGrid.prototype.init = function()
  6. {
  7.    this.pData = new Array(0,0,0,0,0,0,0,0,0);
  8. };
  9. SmallGrid.prototype.reorder = function()
  10. {
  11.    x = 0;
  12.    while(x < 3)
  13.    {
  14.       var _loc3_ = 0;
  15.       y = 0;
  16.       while(y < 3)
  17.       {
  18.          var _loc2_ = x + y * 3;
  19.          if(this.pData[_loc2_] == 0)
  20.          {
  21.             _loc3_ = _loc3_ + 1;
  22.          }
  23.          else if(_loc3_ > 0)
  24.          {
  25.             this.pData[_loc2_ - _loc3_ * 3] = this.pData[_loc2_] + 0;
  26.             this.pData[_loc2_] = 0;
  27.          }
  28.          y++;
  29.       }
  30.       x++;
  31.    }
  32. };
  33. SmallGrid.prototype.clearGrid = function()
  34. {
  35.    var _loc2_ = 0;
  36.    while(_loc2_ < 9)
  37.    {
  38.       this.pData[_loc2_] = 0;
  39.       _loc2_ = _loc2_ + 1;
  40.    }
  41. };
  42. SmallGrid.prototype.checkGrid = function()
  43. {
  44.    var _loc5_ = undefined;
  45.    var _loc4_ = undefined;
  46.    var _loc3_ = undefined;
  47.    var _loc2_ = undefined;
  48.    var _loc6_ = new Array();
  49.    _loc5_ = 0;
  50.    while(_loc5_ < 9)
  51.    {
  52.       _loc4_ = _loc5_ - Math.floor(_loc5_ / 3);
  53.       _loc3_ = _loc5_ % 3;
  54.       _loc2_ = this.getCellColour(_loc4_);
  55.       if(_loc2_ != 0)
  56.       {
  57.          if(this.getCellColour(_loc4_ + 1) == _loc2_ && this.getCellColour(_loc4_ + 2) == _loc2_)
  58.          {
  59.             _loc6_.push(_loc4_,_loc4_ + 1,_loc4_ + 2);
  60.          }
  61.       }
  62.       _loc2_ = this.getCellColour(_loc3_);
  63.       if(_loc2_ != 0)
  64.       {
  65.          if(this.getCellColour(_loc3_ + 3) == _loc2_ && this.getCellColour(_loc3_ + 6) == _loc2_)
  66.          {
  67.             _loc6_.push(_loc3_,_loc3_ + 3,_loc3_ + 6);
  68.          }
  69.       }
  70.       _loc5_ += 4;
  71.    }
  72.    return _loc6_;
  73. };
  74. SmallGrid.prototype.removeBlocks = function()
  75. {
  76.    var _loc9_ = new Array([],[]);
  77.    var _loc10_ = this.pData.slice();
  78.    var _loc3_ = this.pColours.slice();
  79.    var _loc5_ = undefined;
  80.    var _loc2_ = undefined;
  81.    var _loc8_ = undefined;
  82.    var _loc7_ = 6;
  83.    while(_loc7_ < 9)
  84.    {
  85.       _loc5_ = 0;
  86.       _loc2_ = _loc7_ + 0;
  87.       _loc8_ = 0;
  88.       while(_loc2_ >= 0)
  89.       {
  90.          if(_loc10_[_loc2_] == 0)
  91.          {
  92.             if(_loc3_.length == 0)
  93.             {
  94.                _loc3_ = this.pColours.slice();
  95.             }
  96.             else
  97.             {
  98.                var _loc4_ = _loc3_[Math.round(Math.random() * (_loc3_.length - 1))];
  99.                _loc3_.splice(_loc3_.getItemIndex(_loc4_),1);
  100.             }
  101.             var _loc6_ = _loc7_ - 6 + _loc8_ * 3;
  102.             _loc9_[1].push(new Array(_loc2_,_loc6_,_loc4_));
  103.             this.pData[_loc6_] = _loc4_;
  104.             _loc8_ = _loc8_ + 1;
  105.             _loc5_ = _loc5_ + 1;
  106.          }
  107.          else if(_loc5_ > 0)
  108.          {
  109.             _loc9_[0].push(new Array(_loc2_,_loc5_));
  110.             this.pData[_loc2_ + _loc5_ * 3] = _loc10_[_loc2_];
  111.          }
  112.          _loc2_ -= 3;
  113.       }
  114.       _loc7_ = _loc7_ + 1;
  115.    }
  116.    return _loc9_;
  117. };
  118. SmallGrid.prototype.checkBlocks = function(tCellNum)
  119. {
  120.    var _loc12_ = undefined;
  121.    var _loc11_ = undefined;
  122.    var _loc6_ = undefined;
  123.    var _loc14_ = undefined;
  124.    var _loc16_ = undefined;
  125.    var _loc15_ = undefined;
  126.    var _loc17_ = undefined;
  127.    var _loc3_ = undefined;
  128.    var _loc7_ = undefined;
  129.    var _loc8_ = undefined;
  130.    var _loc10_ = undefined;
  131.    var _loc9_ = undefined;
  132.    _loc12_ = new Array();
  133.    _loc11_ = new Array();
  134.    _loc6_ = this.getCellColour(tCellNum);
  135.    _loc14_ = Math.floor(tCellNum / 3);
  136.    _loc16_ = 2 - _loc14_;
  137.    _loc15_ = tCellNum - Math.floor(tCellNum / 3) * 3;
  138.    _loc17_ = 2 - _loc15_;
  139.    _loc7_ = 1;
  140.    while(_loc7_ <= _loc14_)
  141.    {
  142.       _loc3_ = tCellNum - _loc7_ * 3;
  143.       if(this.getCellColour(_loc3_) != _loc6_)
  144.       {
  145.          break;
  146.       }
  147.       _loc11_.push(_loc3_);
  148.       _loc7_ = _loc7_ + 1;
  149.    }
  150.    _loc8_ = 1;
  151.    while(_loc8_ <= _loc16_)
  152.    {
  153.       _loc3_ = tCellNum + _loc8_ * 3;
  154.       if(this.getCellColour(_loc3_) != _loc6_)
  155.       {
  156.          break;
  157.       }
  158.       _loc11_.push(_loc3_);
  159.       _loc8_ = _loc8_ + 1;
  160.    }
  161.    _loc10_ = 1;
  162.    while(_loc10_ <= _loc15_)
  163.    {
  164.       _loc3_ = tCellNum - _loc10_;
  165.       if(this.getCellColour(_loc3_) != _loc6_)
  166.       {
  167.          break;
  168.       }
  169.       _loc12_.push(_loc3_);
  170.       _loc10_ = _loc10_ + 1;
  171.    }
  172.    _loc9_ = 1;
  173.    while(_loc9_ <= _loc17_)
  174.    {
  175.       _loc3_ = tCellNum + _loc9_;
  176.       if(this.getCellColour(_loc3_) != _loc6_)
  177.       {
  178.          break;
  179.       }
  180.       _loc12_.push(_loc3_);
  181.       _loc9_ = _loc9_ + 1;
  182.    }
  183.    var _loc13_ = new Array();
  184.    _loc13_.push(tCellNum);
  185.    if(_loc12_.length >= 2)
  186.    {
  187.       _loc13_ = _loc13_.concat(_loc12_);
  188.       _parent.scores_mc.updateBonus();
  189.       _parent.scores_mc.updateScore(_loc12_.length + 1);
  190.       _parent.fuse_mc.addFuse(_loc12_.length + 1);
  191.       updateBlockCount();
  192.    }
  193.    if(_loc11_.length >= 2)
  194.    {
  195.       _loc13_ = _loc13_.concat(_loc11_);
  196.       _parent.scores_mc.updateBonus();
  197.       _parent.scores_mc.updateScore(_loc11_.length + 1);
  198.       _parent.fuse_mc.addFuse(_loc11_.length + 1);
  199.       updateBlockCount();
  200.    }
  201.    if(_loc13_.length > 1)
  202.    {
  203.       var _loc18_ = _loc13_.length;
  204.       var _loc4_ = 0;
  205.       while(_loc4_ < _loc18_)
  206.       {
  207.          this.pData[_loc13_[_loc4_]] = 0;
  208.          _loc4_ = _loc4_ + 1;
  209.       }
  210.    }
  211.    return _loc13_;
  212. };
  213. SmallGrid.prototype.swapBlocks = function(tCellID1, tCellID2)
  214. {
  215.    var _loc3_ = this.getCellColour(tCellID1);
  216.    var _loc2_ = this.getCellColour(tCellID2);
  217.    this.pData[tCellID1] = _loc2_;
  218.    this.pData[tCellID2] = _loc3_;
  219. };
  220. SmallGrid.prototype.fillGrid = function()
  221. {
  222.    var _loc3_ = undefined;
  223.    var _loc5_ = undefined;
  224.    var _loc6_ = undefined;
  225.    var _loc4_ = undefined;
  226.    var _loc2_ = 0;
  227.    while(_loc2_ < 9)
  228.    {
  229.       _loc3_ = this.pColours.slice();
  230.       if(Math.round(_loc2_ % 3) > 1)
  231.       {
  232.          _loc6_ = this.getCellColour(_loc2_ - 1);
  233.          if(_loc6_ - this.getCellColour(_loc2_ - 2) == 0)
  234.          {
  235.             _loc4_ = _loc3_.getItemIndex(_loc6_);
  236.             _loc3_.splice(_loc4_,1);
  237.          }
  238.       }
  239.       if(Math.floor(_loc2_ / 3) > 1)
  240.       {
  241.          _loc5_ = this.getCellColour(_loc2_ - 3);
  242.          if(_loc5_ - this.getCellColour(_loc2_ - 6) == 0)
  243.          {
  244.             _loc4_ = _loc3_.getItemIndex(_loc5_);
  245.             _loc3_.splice(_loc4_,1);
  246.          }
  247.       }
  248.       this.pData[_loc2_] = _loc3_[Math.round(Math.random() * (_loc3_.length - 1))];
  249.       _loc2_ = _loc2_ + 1;
  250.    }
  251. };
  252. SmallGrid.prototype.getCellColour = function(aNum)
  253. {
  254.    var _loc2_ = this.pData[aNum];
  255.    return _loc2_;
  256. };
  257. SmallGrid.prototype.setCellColour = function(aId, aColour)
  258. {
  259.    this.pData[aId] = aColour + 0;
  260. };
  261. SmallGrid.prototype.printGrid = function()
  262. {
  263.    var _loc3_ = "";
  264.    var _loc4_ = 0;
  265.    while(_loc4_ < 3)
  266.    {
  267.       _loc3_ = "";
  268.       var _loc2_ = 0;
  269.       while(_loc2_ < 3)
  270.       {
  271.          _loc3_ += this.getCellColour(_loc4_ * 3 + _loc2_);
  272.          _loc2_ = _loc2_ + 1;
  273.       }
  274.       _loc4_ = _loc4_ + 1;
  275.    }
  276. };
  277. this.init = function()
  278. {
  279.    this.pGrid = new SmallGrid();
  280.    this.pBlockCount = 0;
  281.    this.pSpaces = new Array(0,0,0,0,0,0,0,0,0);
  282.    this.pTileLocs = new Array(9);
  283.    this.pTileCheck = 0;
  284.    this.pClearedTiles = new Array();
  285.    this.setMask(this.soulMask_mc);
  286.    var _loc3_ = undefined;
  287.    var _loc2_ = 0;
  288.    while(_loc2_ < 9)
  289.    {
  290.       _loc3_ = new Object();
  291.       _loc3_.pNum = _loc2_;
  292.       _loc3_.pPos = new Object();
  293.       _loc3_.pPos.x = -40 + 40 * (_loc2_ % 3);
  294.       _loc3_.pPos.y = 40 - 40 * Math.floor(_loc2_ / 3);
  295.       _loc3_.pColour = _loc2_ + 1;
  296.       this.attachMovie("mc.tile","t" + _loc2_ + "_mc",_loc2_,_loc3_);
  297.       this.pTileLocs[_loc2_] = "t" + _loc2_ + "_mc";
  298.       _loc2_ = _loc2_ + 1;
  299.    }
  300. };
  301. this.clearMap = function()
  302. {
  303.    var _loc2_ = 0;
  304.    while(_loc2_ < 9)
  305.    {
  306.       this[this.pTileLocs[_loc2_]].hideTile();
  307.       this.pSpaces[_loc2_] = 0;
  308.       _loc2_ = _loc2_ + 1;
  309.    }
  310.    this.pBlockCount = 0;
  311.    this.pGrid.clearGrid();
  312. };
  313. this.addTile = function(tTileC)
  314. {
  315.    if(this.pBlockCount < 9)
  316.    {
  317.       this.pBlockCount = this.pBlockCount + 1;
  318.       var _loc2_ = this.pSpaces.getItemIndex(0);
  319.       this[this.pTileLocs[_loc2_]].placeTile(140,tTileC);
  320.       this.pSpaces[_loc2_] = 1;
  321.       this.pGrid.setCellColour(_loc2_,tTileC);
  322.       this.pTileCheck = this.pTileCheck + 1;
  323.    }
  324. };
  325. this.tileScaleDone = function()
  326. {
  327.    if(--this.pTileCheck == 0)
  328.    {
  329.       var _loc8_ = this.pClearedTiles.length / 3;
  330.       var _loc6_ = 0;
  331.       while(_loc6_ < _loc8_)
  332.       {
  333.          var _loc7_ = this.pClearedTiles[_loc6_ * 3];
  334.          if(_loc7_ < 6)
  335.          {
  336.             if(_loc7_ == this.pClearedTiles[_loc6_ * 3 + 1] - 1)
  337.             {
  338.                var _loc4_ = 0;
  339.                while(_loc4_ < 3)
  340.                {
  341.                   var _loc5_ = (_loc6_ * 3 + _loc4_) % 3;
  342.                   var _loc3_ = 0;
  343.                   var _loc2_ = _loc5_;
  344.                   while(_loc2_ < _loc5_ + 7)
  345.                   {
  346.                      if(this.pSpaces[_loc2_] == 0)
  347.                      {
  348.                         _loc3_ = _loc3_ + 1;
  349.                      }
  350.                      else if(_loc3_ > 0)
  351.                      {
  352.                         this[this.pTileLocs[_loc2_]].hideTile();
  353.                         this[this.pTileLocs[_loc2_ - _loc3_ * 3]].placeTile(40,this.pGrid.getCellColour(_loc2_));
  354.                         this.pSpaces[_loc2_] = 0;
  355.                         this.pSpaces[_loc2_ - _loc3_ * 3] = 1;
  356.                         this.pTileCheck = this.pTileCheck + 1;
  357.                      }
  358.                      _loc2_ += 3;
  359.                   }
  360.                   _loc4_ = _loc4_ + 1;
  361.                }
  362.                this.pGrid.reorder();
  363.             }
  364.          }
  365.          _loc6_ = _loc6_ + 1;
  366.       }
  367.    }
  368. };
  369. this.tileDropDone = function()
  370. {
  371.    if(--this.pTileCheck == 0)
  372.    {
  373.       var _loc3_ = this.pGrid.checkGrid();
  374.       var _loc4_ = _loc3_.length;
  375.       if(_loc4_ > 0)
  376.       {
  377.          this.pClearedTiles.splice(0);
  378.          var _loc2_ = 0;
  379.          while(_loc2_ < _loc4_)
  380.          {
  381.             this[this.pTileLocs[_loc3_[_loc2_]]].scaleTile();
  382.             this.pGrid.setCellColour(_loc3_[_loc2_],0);
  383.             this.pSpaces[_loc3_[_loc2_]] = 0;
  384.             this.pBlockCount = this.pBlockCount - 1;
  385.             this.pClearedTiles.push(_loc3_[_loc2_]);
  386.             this.pTileCheck = this.pTileCheck + 1;
  387.             _loc2_ = _loc2_ + 1;
  388.          }
  389.          if(this._parent._currentframe > 16)
  390.          {
  391.             this._parent.scores_mc.updateScore(100);
  392.          }
  393.       }
  394.    }
  395. };
  396. this.init();
  397. stop();
  398.